package com.aotain.nyx.apptype;

import org.apache.flink.api.common.functions.ReduceFunction;
import org.apache.flink.api.java.tuple.Tuple2;

import com.aotain.nyx.statis.AbnStatisTuple;

public class AppTypeAllStatisReduce implements ReduceFunction<Tuple2<String,AppTypeTuple>> {

	/** 
	* @Fields serialVersionUID : TODO(用一句话描述这个变量表示什么) 
	*/ 
	private static final long serialVersionUID = 8867731776636270995L;

	@Override
	public Tuple2<String, AppTypeTuple> reduce(
			Tuple2<String, AppTypeTuple> value1,
			Tuple2<String, AppTypeTuple> value2) throws Exception {
		// TODO Auto-generated method stub
		AppTypeTuple tuple = value1.f1;
		if(value1.f1 != null && value2.f1 != null ) {
			tuple.setUpStreamOctets(value1.f1.getUpStreamOctets() + value2.f1.getUpStreamOctets());
			tuple.setUpStreamPacket(value1.f1.getUpStreamPacket() + value2.f1.getUpStreamPacket());
			tuple.setDnStreamOctets(value1.f1.getDnStreamOctets() + value2.f1.getDnStreamOctets());
			tuple.setDnStreamPacket(value1.f1.getDnStreamPacket() + value2.f1.getDnStreamPacket());
		}else {
			System.out.println("reduce arg is null");
		}
		return new Tuple2<String,AppTypeTuple>(value1.f0,tuple);
	}

}
